package com.liaoye.hellocustomview.util;

import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.util.Log;

public class CameraUtil {
    private static final String TAG = CameraUtil.class.getSimpleName();
    /**
     * 检测设备是否存在相机
     * @param context
     * @return
     */
    public static boolean checkCameraHardware(Context context) {
        if(context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)) {
            return true;
        } else {
            return  false;
        }
    }


    /**
     * 获取相机实例
     * @return
     */
    public static Camera getCameraInstance() {
        Camera camera = null;
        try {
            int numberOfCameras = Camera.getNumberOfCameras();
            Log.i(TAG, "getCameraInstance: numberOfCameras= " + numberOfCameras);
            camera = Camera.open();
        } catch (Exception e) {
            Log.i(TAG, "getCameraInstance: " + e.getMessage());
        }
        return camera;
    }

}
